home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Temático 40 Febrero 2004.iso / DOS / testdisk / src / bfs.c < prev    next >
Encoding:
C/C++ Source or Header  |  2004-01-02  |  2.8 KB  |  76 lines

  1. /*
  2.  
  3.     File: bfs.c
  4.  
  5.     Copyright (C) 1998-2004 Christophe GRENIER <grenier@cgsecurity.org>
  6.   
  7.     This software is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.   
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.   
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  */
  22.  
  23. #include "types.h"
  24. #include "common.h"
  25. #include "bfs.h"
  26. #include "intrface.h"
  27. #include "fnctdsk.h"
  28.  
  29. static int set_BeFS_info(t_param_disk *disk_car, const struct disk_super_block *beos_block,t_diskext *partition,const int debug, const int dump_ind);
  30. static int test_BeFS(t_param_disk *disk_car, const struct disk_super_block*beos_block,t_diskext *partition,const int debug, const int dump_ind);
  31.  
  32. int check_BeFS(t_param_disk *disk_car,t_diskext *partition,const int debug)
  33. {
  34.   unsigned char buffer[8*SECTOR_SIZE];
  35.   if(disk_car->read(disk_car,8, &buffer, partition->lba)!=0)
  36.     return 1;
  37.   if(test_BeFS(disk_car,(struct disk_super_block*)&buffer[200],partition,debug,0)!=0)
  38.     return 1;
  39.   set_BeFS_info(disk_car,(struct disk_super_block*)&buffer[200],partition,debug,0);
  40.   return 0;
  41. }
  42.  
  43. int recover_BeFS(t_param_disk *disk_car, const struct disk_super_block *beos_block,t_diskext *partition,const int debug, const int dump_ind)
  44. {
  45.   if(test_BeFS(disk_car,beos_block,partition,debug,dump_ind)!=0)
  46.     return 1;
  47.   set_BeFS_info(disk_car,beos_block,partition,debug,0);
  48.   partition->part_size=beos_block->num_blocks*((1<<beos_block->block_shift)/512);
  49.   partition->part_type=(unsigned char)P_BEOS;
  50.   return 0;
  51. }
  52.  
  53. static int test_BeFS(t_param_disk *disk_car, const struct disk_super_block*beos_block,t_diskext *partition,const int debug, const int dump_ind)
  54. {
  55.   if((beos_block->magic1==SUPER_BLOCK_MAGIC1)
  56.      && (beos_block->magic2==(signed)SUPER_BLOCK_MAGIC2)
  57.      && (beos_block->magic3==SUPER_BLOCK_MAGIC3))
  58.   {
  59.     partition->upart_type=UP_BEOS;
  60.     if(dump_ind!=0)
  61.     {
  62.       ecrit_rapport("\nBeFS magic value at %u/%u/%u\n", LBA2cylinder(disk_car,partition->lba),LBA2head(disk_car,partition->lba),LBA2sector(disk_car,partition->lba));
  63.       dump(stdscr,beos_block,SECTOR_SIZE);
  64.     }
  65.     return 0;
  66.   }
  67.   return 1;
  68. }
  69.  
  70. static int set_BeFS_info(t_param_disk *disk_car, const struct disk_super_block *beos_block,t_diskext *partition,const int debug, const int dump_ind)
  71. {
  72.   partition->info[0]='\0';
  73.   set_part_name(partition,beos_block->name,B_OS_NAME_LENGTH);
  74.   return 0;
  75. }
  76.